<?php

namespace App\Admin\Controllers\Bj;

use App\Admin\Repositories\SwtBjOpen;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class SwtBjOpenController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SwtBjOpen(), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('order_id');
            $grid->column('machine_id');
            $grid->column('event_id');
            $grid->column('event_type')
                ->using([
                    1 => '录制视频',
                    4 => '不录制视频',
                    5 => '检修开锁',
                    6 => '检修关锁'
                ])
                ->dot([
                    1 => 'success',
                    4 => 'danger',
                    5 => 'success',
                    6 => 'danger'
                ]
            );
            $grid->column('device_code');
            $grid->column('cabinet_no');
            $grid->column('open_status')->using(['未知', '成功', '失败'])->label(['info', 'success', 'warning']);;
            $grid->column('failed_msg') -> display(function ($value) {
                return $value ?? '-';
            });
            $grid->column('video_main_url')->video();
            $grid->column('video_auxiliary_url')->video();
            $grid->column('open_time');
            $grid->column('close_time');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('order_id');
            });

            $grid->disableActions();
        });
    }
}
